package com.qianfeng.smartdevice.controller;


import com.qianfeng.smartdevice.dto.R;
import com.qianfeng.smartdevice.exceptions.MyBaseException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
@ResponseBody
public class MyExceptionHandler {

    @ExceptionHandler(MyBaseException.class)
    public R processMyBaseException(MyBaseException e){
        e.printStackTrace();
        return R.setError(e.getCode(), e.getMessage(), null);
    }

    @ExceptionHandler(ArithmeticException.class)
    public R processArithmeticException(ArithmeticException e) {
        e.printStackTrace();
        System.out.println("算数异常");
        return R.setError(null);
    }

    @ExceptionHandler(Exception.class)
    public R processException(Exception e) {
        e.printStackTrace();
        System.out.println("未知异常发生了");
        return R.setError(null);
    }
}
